home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / gdb-4.12 / gdb / symmisc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  22.4 KB  |  858 lines

  1. /* Do various things to symbol tables (other than lookup), for GDB.
  2.    Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "defs.h"
  21. #include "symtab.h"
  22. #include "gdbtypes.h"
  23. #include "bfd.h"
  24. #include "symfile.h"
  25. #include "objfiles.h"
  26. #include "breakpoint.h"
  27. #include "command.h"
  28. #include "obstack.h"
  29. #include "language.h"
  30.  
  31. #include <string.h>
  32.  
  33. #ifndef DEV_TTY
  34. #define DEV_TTY "/dev/tty"
  35. #endif
  36.  
  37. /* Unfortunately for debugging, stderr is usually a macro.  This is painful
  38.    when calling functions that take FILE *'s from the debugger.
  39.    So we make a variable which has the same value and which is accessible when
  40.    debugging GDB with itself.  Because stdin et al need not be constants,
  41.    we initialize them in the _initialize_symmisc function at the bottom
  42.    of the file.  */
  43. FILE *std_in;
  44. FILE *std_out;
  45. FILE *std_err;
  46.  
  47. /* Prototypes for local functions */
  48.  
  49. static void 
  50. dump_symtab PARAMS ((struct objfile *, struct symtab *, GDB_FILE *));
  51.  
  52. static void 
  53. dump_psymtab PARAMS ((struct objfile *, struct partial_symtab *, GDB_FILE *));
  54.  
  55. static void 
  56. dump_msymbols PARAMS ((struct objfile *, GDB_FILE *));
  57.  
  58. static void 
  59. dump_objfile PARAMS ((struct objfile *));
  60.  
  61. static int
  62. block_depth PARAMS ((struct block *));
  63.  
  64. static void
  65. print_partial_symbol PARAMS ((struct partial_symbol *, int, char *, GDB_FILE *));
  66.  
  67. struct print_symbol_args {
  68.   struct symbol *symbol;
  69.   int depth;
  70.   GDB_FILE *outfile;
  71. };
  72.  
  73. static int print_symbol PARAMS ((char *));
  74.  
  75. static void
  76. free_symtab_block PARAMS ((struct objfile *, struct block *));
  77.  
  78.  
  79. /* Free a struct block <- B and all the symbols defined in that block.  */
  80.  
  81. static void
  82. free_symtab_block (objfile, b)
  83.      struct objfile *objfile;
  84.      struct block *b;
  85. {
  86.   register int i, n;
  87.   n = BLOCK_NSYMS (b);
  88.   for (i = 0; i < n; i++)
  89.     {
  90.       mfree (objfile -> md, SYMBOL_NAME (BLOCK_SYM (b, i)));
  91.       mfree (objfile -> md, (PTR) BLOCK_SYM (b, i));
  92.     }
  93.   mfree (objfile -> md, (PTR) b);
  94. }
  95.  
  96. /* Free all the storage associated with the struct symtab <- S.
  97.    Note that some symtabs have contents malloc'ed structure by structure,
  98.    while some have contents that all live inside one big block of memory,
  99.    and some share the contents of another symbol table and so you should
  100.    not free the contents on their behalf (except sometimes the linetable,
  101.    which maybe per symtab even when the rest is not).
  102.    It is s->free_code that says which alternative to use.  */
  103.  
  104. void
  105. free_symtab (s)
  106.      register struct symtab *s;
  107. {
  108.   register int i, n;
  109.   register struct blockvector *bv;
  110.  
  111.   switch (s->free_code)
  112.     {
  113.     case free_nothing:
  114.       /* All the contents are part of a big block of memory (an obstack),
  115.      and some other symtab is in charge of freeing that block.
  116.      Therefore, do nothing.  */
  117.       break;
  118.  
  119.     case free_contents:
  120.       /* Here all the contents were malloc'ed structure by structure
  121.      and must be freed that way.  */
  122.       /* First free the blocks (and their symbols.  */
  123.       bv = BLOCKVECTOR (s);
  124.       n = BLOCKVECTOR_NBLOCKS (bv);
  125.       for (i = 0; i < n; i++)
  126.     free_symtab_block (s -> objfile, BLOCKVECTOR_BLOCK (bv, i));
  127.       /* Free the blockvector itself.  */
  128.       mfree (s -> objfile -> md, (PTR) bv);
  129.       /* Also free the linetable.  */
  130.       
  131.     case free_linetable:
  132.       /* Everything will be freed either by our `free_ptr'
  133.      or by some other symtab, except for our linetable.
  134.      Free that now.  */
  135.       if (LINETABLE (s))
  136.     mfree (s -> objfile -> md, (PTR) LINETABLE (s));
  137.       break;
  138.     }
  139.  
  140.   /* If there is a single block of memory to free, free it.  */
  141.   if (s -> free_ptr != NULL)
  142.     mfree (s -> objfile -> md, s -> free_ptr);
  143.  
  144.   /* Free source-related stuff */
  145.   if (s -> line_charpos != NULL)
  146.     mfree (s -> objfile -> md, (PTR) s -> line_charpos);
  147.   if (s -> fullname != NULL)
  148.     mfree (s -> objfile -> md, s -> fullname);
  149.   mfree (s -> objfile -> md, (PTR) s);
  150. }
  151.  
  152. #if MAINTENANCE_CMDS
  153.  
  154. static void 
  155. dump_objfile (objfile)
  156.      struct objfile *objfile;
  157. {
  158.   struct symtab *symtab;
  159.   struct partial_symtab *psymtab;
  160.  
  161.   printf_filtered ("\nObject file %s:  ", objfile -> name);
  162.   printf_filtered ("Objfile at %lx, bfd at %lx, %d minsyms\n\n",
  163.            (unsigned long) objfile,
  164.            (unsigned long) objfile -> obfd,
  165.            objfile->minimal_symbol_count);
  166.  
  167.   if (objfile -> psymtabs)
  168.     {
  169.       printf_filtered ("Psymtabs:\n");
  170.       for (psymtab = objfile -> psymtabs;
  171.        psymtab != NULL;
  172.        psymtab = psymtab -> next)
  173.     {
  174.       printf_filtered ("%s at %lx, ",
  175.                psymtab -> filename, (unsigned long) psymtab);
  176.       if (psymtab -> objfile != objfile)
  177.         {
  178.           printf_filtered ("NOT ON CHAIN!  ");
  179.         }
  180.       wrap_here ("  ");
  181.     }
  182.       printf_filtered ("\n\n");
  183.     }
  184.  
  185.   if (objfile -> symtabs)
  186.     {
  187.       printf_filtered ("Symtabs:\n");
  188.       for (symtab = objfile -> symtabs;
  189.        symtab != NULL;
  190.        symtab = symtab->next)
  191.     {
  192.       printf_filtered ("%s at %lx, ",
  193.                symtab -> filename, (unsigned long) symtab);
  194.       if (symtab -> objfile != objfile)
  195.         {
  196.           printf_filtered ("NOT ON CHAIN!  ");
  197.         }
  198.       wrap_here ("  ");
  199.     }
  200.       printf_filtered ("\n\n");
  201.     }
  202. }
  203.  
  204. /* Print minimal symbols from this objfile.  */
  205.  
  206. static void 
  207. dump_msymbols (objfile, outfile)
  208.      struct objfile *objfile;
  209.      GDB_FILE *outfile;
  210. {
  211.   struct minimal_symbol *msymbol;
  212.   int index;
  213.   char ms_type;
  214.   
  215.   fprintf_filtered (outfile, "\nObject file %s:\n\n", objfile -> name);
  216.   if (objfile -> minimal_symbol_count == 0)
  217.     {
  218.       fprintf_filtered (outfile, "No minimal symbols found.\n");
  219.       return;
  220.     }
  221.   for (index = 0, msymbol = objfile -> msymbols;
  222.        SYMBOL_NAME (msymbol) != NULL; msymbol++, index++)
  223.     {
  224.       switch (msymbol -> type)
  225.     {
  226.       case mst_unknown:
  227.         ms_type = 'u';
  228.         break;
  229.       case mst_text:
  230.         ms_type = 'T';
  231.         break;
  232.       case mst_data:
  233.         ms_type = 'D';
  234.         break;
  235.       case mst_bss:
  236.         ms_type = 'B';
  237.         break;
  238.       case mst_abs:
  239.         ms_type = 'A';
  240.         break;
  241.       case mst_file_text:
  242.         ms_type = 't';
  243.         break;
  244.       case mst_file_data:
  245.         ms_type = 'd';
  246.         break;
  247.       case mst_file_bss:
  248.         ms_type = 'b';
  249.         break;
  250.       default:
  251.         ms_type = '?';
  252.         break;
  253.     }
  254.       fprintf_filtered (outfile, "[%2d] %c %#10lx %s", index, ms_type,
  255.             SYMBOL_VALUE_ADDRESS (msymbol), SYMBOL_NAME (msymbol));
  256.       if (SYMBOL_DEMANGLED_NAME (msymbol) != NULL)
  257.     {
  258.       fprintf_filtered (outfile, "  %s", SYMBOL_DEMANGLED_NAME (msymbol));
  259.     }
  260.       fputs_filtered ("\n", outfile);
  261.     }
  262.   if (objfile -> minimal_symbol_count != index)
  263.     {
  264.       warning ("internal error:  minimal symbol count %d != %d",
  265.            objfile -> minimal_symbol_count, index);
  266.     }
  267.   fprintf_filtered (outfile, "\n");
  268. }
  269.  
  270. static void
  271. dump_psymtab (objfile, psymtab, outfile)
  272.      struct objfile *objfile;
  273.      struct partial_symtab *psymtab;
  274.      GDB_FILE *outfile;
  275. {
  276.   int i;
  277.  
  278.   fprintf_filtered (outfile, "\nPartial symtab for source file %s ",
  279.             psymtab -> filename);
  280.   fprintf_filtered (outfile, "(object 0x%lx)\n\n", (unsigned long) psymtab);
  281.   fprintf_unfiltered (outfile, "  Read from object file %s (0x%lx)\n",
  282.        objfile -> name, (unsigned long) objfile);
  283.   
  284.   if (psymtab -> readin)
  285.     {
  286.       fprintf_filtered (outfile,
  287.         "  Full symtab was read (at 0x%lx by function at 0x%lx)\n",
  288.             (unsigned long) psymtab -> symtab,
  289.             (unsigned long) psymtab -> read_symtab);
  290.     }
  291.  
  292.   /* FIXME, we need to be able to print the relocation stuff. */
  293.   /* This prints some garbage for anything but stabs right now.  FIXME.  */
  294.   if (psymtab->section_offsets)
  295.     fprintf_filtered (outfile,
  296.               "  Relocate symbols by 0x%lx, 0x%lx, 0x%lx, 0x%lx.\n",
  297.               (unsigned long) ANOFFSET (psymtab->section_offsets, 0),
  298.               (unsigned long) ANOFFSET (psymtab->section_offsets, 1),
  299.               (unsigned long) ANOFFSET (psymtab->section_offsets, 2),
  300.               (unsigned long) ANOFFSET (psymtab->section_offsets, 3));
  301.  
  302.   fprintf_filtered (outfile, "  Symbols cover text addresses 0x%lx-0x%lx\n",
  303.             (unsigned long) psymtab -> textlow,
  304.             (unsigned long) psymtab -> texthigh);
  305.   fprintf_filtered (outfile, "  Depends on %d other partial symtabs.\n",
  306.             psymtab -> number_of_dependencies);
  307.   for (i = 0; i < psymtab -> number_of_dependencies; i++)
  308.     {
  309.       fprintf_filtered (outfile, "    %d 0x%lx %s\n", i,
  310.             (unsigned long) psymtab -> dependencies[i],
  311.             psymtab -> dependencies[i] -> filename);
  312.     }
  313.   if (psymtab -> n_global_syms > 0)
  314.     {
  315.       print_partial_symbol (objfile -> global_psymbols.list
  316.                 + psymtab -> globals_offset,
  317.                 psymtab -> n_global_syms, "Global", outfile);
  318.     }
  319.   if (psymtab -> n_static_syms > 0)
  320.     {
  321.       print_partial_symbol (objfile -> static_psymbols.list
  322.                 + psymtab -> statics_offset,
  323.                 psymtab -> n_static_syms, "Static", outfile);
  324.     }
  325.   fprintf_filtered (outfile, "\n");
  326. }
  327.  
  328. static void 
  329. dump_symtab (objfile, symtab, outfile)
  330.      struct objfile *objfile;
  331.      struct symtab *symtab;
  332.      GDB_FILE *outfile;
  333. {
  334.   register int i, j;
  335.   int len, blen;
  336.   register struct linetable *l;
  337.   struct blockvector *bv;
  338.   register struct block *b;
  339.   int depth;
  340.  
  341.   fprintf_unfiltered (outfile, "\nSymtab for file %s\n", symtab->filename);
  342.   fprintf_unfiltered (outfile, "Read from object file %s (%lx)\n", objfile->name,
  343.        (unsigned long) objfile);
  344.   fprintf_unfiltered (outfile, "Language: %s\n", language_str (symtab -> language));
  345.   
  346.   /* First print the line table.  */
  347.   l = LINETABLE (symtab);
  348.   if (l) {
  349.     fprintf_unfiltered (outfile, "\nLine table:\n\n");
  350.     len = l->nitems;
  351.     for (i = 0; i < len; i++)
  352.       fprintf_unfiltered (outfile, " line %d at %lx\n", l->item[i].line,
  353.               (unsigned long) l->item[i].pc);
  354.   }
  355.   /* Now print the block info.  */
  356.   fprintf_unfiltered (outfile, "\nBlockvector:\n\n");
  357.   bv = BLOCKVECTOR (symtab);
  358.   len = BLOCKVECTOR_NBLOCKS (bv);
  359.   for (i = 0; i < len; i++)
  360.     {
  361.       b = BLOCKVECTOR_BLOCK (bv, i);
  362.       depth = block_depth (b) * 2;
  363.       print_spaces (depth, outfile);
  364.       fprintf_unfiltered (outfile, "block #%03d (object 0x%lx) ", i, (unsigned long) b);
  365.       fprintf_unfiltered (outfile, "[0x%lx..0x%lx]",
  366.            (unsigned long) BLOCK_START (b),
  367.            (unsigned long) BLOCK_END (b));
  368.       if (BLOCK_SUPERBLOCK (b))
  369.     fprintf_unfiltered (outfile, " (under 0x%lx)",
  370.          (unsigned long) BLOCK_SUPERBLOCK (b));
  371.       if (BLOCK_FUNCTION (b))
  372.     {
  373.       fprintf_unfiltered (outfile, " %s", SYMBOL_NAME (BLOCK_FUNCTION (b)));
  374.       if (SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)) != NULL)
  375.         {
  376.           fprintf_unfiltered (outfile, " %s",
  377.                SYMBOL_DEMANGLED_NAME (BLOCK_FUNCTION (b)));
  378.         }
  379.     }
  380.       if (BLOCK_GCC_COMPILED(b))
  381.     fprintf_unfiltered (outfile, " gcc%d compiled", BLOCK_GCC_COMPILED(b));
  382.       fputc_unfiltered ('\n', outfile);
  383.       blen = BLOCK_NSYMS (b);
  384.       for (j = 0; j < blen; j++)
  385.     {
  386.       struct print_symbol_args s;
  387.       s.symbol = BLOCK_SYM (b, j);
  388.       s.depth = depth + 1;
  389.       s.outfile = outfile;
  390.       catch_errors (print_symbol, &s, "Error printing symbol:\n",
  391.             RETURN_MASK_ERROR);
  392.     }
  393.     }
  394.   fprintf_unfiltered (outfile, "\n");
  395. }
  396.  
  397. void
  398. maintenance_print_symbols (args, from_tty)
  399.      char *args;
  400.      int from_tty;
  401. {
  402.   char **argv;
  403.   GDB_FILE *outfile;
  404.   struct cleanup *cleanups;
  405.   char *symname = NULL;
  406.   char *filename = DEV_TTY;
  407.   struct objfile *objfile;
  408.   struct symtab *s;
  409.  
  410.   dont_repeat ();
  411.  
  412.   if (args == NULL)
  413.     {
  414.       error ("print-symbols takes an output file name and optional symbol file name");
  415.     }
  416.   else if ((argv = buildargv (args)) == NULL)
  417.     {
  418.       nomem (0);
  419.     }
  420.   cleanups = make_cleanup (freeargv, (char *) argv);
  421.  
  422.   if (argv[0] != NULL)
  423.     {
  424.       filename = argv[0];
  425.       /* If a second arg is supplied, it is a source file name to match on */
  426.       if (argv[1] != NULL)
  427.     {
  428.       symname = argv[1];
  429.     }
  430.     }
  431.  
  432.   filename = tilde_expand (filename);
  433.   make_cleanup (free, filename);
  434.   
  435.   outfile = gdb_fopen (filename, FOPEN_WT);
  436.   if (outfile == 0)
  437.     perror_with_name (filename);
  438.   make_cleanup (fclose, (char *) outfile);
  439.  
  440.   immediate_quit++;
  441.   ALL_SYMTABS (objfile, s)
  442.     if (symname == NULL || (STREQ (symname, s -> filename)))
  443.       dump_symtab (objfile, s, outfile);
  444.   immediate_quit--;
  445.   do_cleanups (cleanups);
  446. }
  447.  
  448. /* Print symbol ARGS->SYMBOL on ARGS->OUTFILE.  ARGS->DEPTH says how
  449.    far to indent.  ARGS is really a struct print_symbol_args *, but is
  450.    declared as char * to get it past catch_errors.  Returns 0 for error,
  451.    1 for success.  */
  452.  
  453. static int
  454. print_symbol (args)
  455.      char *args;
  456. {
  457.   struct symbol *symbol = ((struct print_symbol_args *)args)->symbol;
  458.   int depth = ((struct print_symbol_args *)args)->depth;
  459.   GDB_FILE *outfile = ((struct print_symbol_args *)args)->outfile;
  460.  
  461.   print_spaces (depth, outfile);
  462.   if (SYMBOL_NAMESPACE (symbol) == LABEL_NAMESPACE)
  463.     {
  464.       fprintf_unfiltered (outfile, "label %s at 0x%lx\n", SYMBOL_SOURCE_NAME (symbol),
  465.            (unsigned long) SYMBOL_VALUE_ADDRESS (symbol));
  466.       return 1;
  467.     }
  468.   if (SYMBOL_NAMESPACE (symbol) == STRUCT_NAMESPACE)
  469.     {
  470.       if (TYPE_TAG_NAME (SYMBOL_TYPE (symbol)))
  471.     {
  472.       LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
  473.     }
  474.       else
  475.     {
  476.       fprintf_unfiltered (outfile, "%s %s = ",
  477.            (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_ENUM
  478.         ? "enum"
  479.         : (TYPE_CODE (SYMBOL_TYPE (symbol)) == TYPE_CODE_STRUCT
  480.            ? "struct" : "union")),
  481.            SYMBOL_NAME (symbol));
  482.       LA_PRINT_TYPE (SYMBOL_TYPE (symbol), "", outfile, 1, depth);
  483.     }
  484.       fprintf_unfiltered (outfile, ";\n");
  485.     }
  486.   else
  487.     {
  488.       if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
  489.     fprintf_unfiltered (outfile, "typedef ");
  490.       if (SYMBOL_TYPE (symbol))
  491.     {
  492.       /* Print details of types, except for enums where it's clutter.  */
  493.       LA_PRINT_TYPE (SYMBOL_TYPE (symbol), SYMBOL_SOURCE_NAME (symbol),
  494.              outfile,
  495.              TYPE_CODE (SYMBOL_TYPE (symbol)) != TYPE_CODE_ENUM,
  496.              depth);
  497.       fprintf_unfiltered (outfile, "; ");
  498.     }
  499.       else
  500.     fprintf_unfiltered (outfile, "%s ", SYMBOL_SOURCE_NAME (symbol));
  501.  
  502.       switch (SYMBOL_CLASS (symbol))
  503.     {
  504.     case LOC_CONST:
  505.       fprintf_unfiltered (outfile, "const %ld (0x%lx),",
  506.            SYMBOL_VALUE (symbol),
  507.            (unsigned long) SYMBOL_VALUE (symbol));
  508.       break;
  509.  
  510.     case LOC_CONST_BYTES:
  511.       fprintf_unfiltered (outfile, "const %u hex bytes:",
  512.            TYPE_LENGTH (SYMBOL_TYPE (symbol)));
  513.       {
  514.         unsigned i;
  515.         for (i = 0; i < TYPE_LENGTH (SYMBOL_TYPE (symbol)); i++)
  516.           fprintf_unfiltered (outfile, " %02x",
  517.              (unsigned)SYMBOL_VALUE_BYTES (symbol) [i]);
  518.         fprintf_unfiltered (outfile, ",");
  519.       }
  520.       break;
  521.  
  522.     case LOC_STATIC:
  523.       fprintf_unfiltered (outfile, "static at 0x%lx,",
  524.            (unsigned long) SYMBOL_VALUE_ADDRESS (symbol));
  525.       break;
  526.  
  527.     case LOC_REGISTER:
  528.       fprintf_unfiltered (outfile, "register %ld,", SYMBOL_VALUE (symbol));
  529.       break;
  530.  
  531.     case LOC_ARG:
  532.       fprintf_unfiltered (outfile, "arg at 0x%lx,", SYMBOL_VALUE (symbol));
  533.       break;
  534.  
  535.     case LOC_LOCAL_ARG:
  536.       fprintf_unfiltered (outfile, "arg at offset 0x%lx from fp,",
  537.            SYMBOL_VALUE (symbol));
  538.       break;
  539.  
  540.     case LOC_REF_ARG:
  541.       fprintf_unfiltered (outfile, "reference arg at 0x%lx,", SYMBOL_VALUE (symbol));
  542.       break;
  543.  
  544.     case LOC_REGPARM:
  545.       fprintf_unfiltered (outfile, "parameter register %ld,", SYMBOL_VALUE (symbol));
  546.       break;
  547.  
  548.     case LOC_REGPARM_ADDR:
  549.       fprintf_unfiltered (outfile, "address parameter register %ld,", SYMBOL_VALUE (symbol));
  550.       break;
  551.  
  552.     case LOC_LOCAL:
  553.       fprintf_unfiltered (outfile, "local at 0x%lx,", SYMBOL_VALUE (symbol));
  554.       break;
  555.  
  556.     case LOC_BASEREG:
  557.       fprintf_unfiltered (outfile, "local at 0x%lx from register %d",
  558.            SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
  559.       break;
  560.  
  561.     case LOC_BASEREG_ARG:
  562.       fprintf_unfiltered (outfile, "arg at 0x%lx from register %d,",
  563.            SYMBOL_VALUE (symbol), SYMBOL_BASEREG (symbol));
  564.       break;
  565.  
  566.     case LOC_TYPEDEF:
  567.       break;
  568.  
  569.     case LOC_LABEL:
  570.       fprintf_unfiltered (outfile, "label at 0x%lx",
  571.            (unsigned long) SYMBOL_VALUE_ADDRESS (symbol));
  572.       break;
  573.  
  574.     case LOC_BLOCK:
  575.       fprintf_unfiltered (outfile, "block (object 0x%lx) starting at 0x%lx,",
  576.            (unsigned long) SYMBOL_BLOCK_VALUE (symbol),
  577.            (unsigned long) BLOCK_START (SYMBOL_BLOCK_VALUE (symbol)));
  578.       break;
  579.  
  580.     case LOC_OPTIMIZED_OUT:
  581.       fprintf_unfiltered (outfile, "optimized out");
  582.       break;
  583.  
  584.         default:
  585.       fprintf_unfiltered (outfile, "botched symbol class %x", SYMBOL_CLASS (symbol));
  586.       break;
  587.     }
  588.     }
  589.   fprintf_unfiltered (outfile, "\n");
  590.   return 1;
  591. }
  592.  
  593. void
  594. maintenance_print_psymbols (args, from_tty)
  595.      char *args;
  596.      int from_tty;
  597. {
  598.   char **argv;
  599.   GDB_FILE *outfile;
  600.   struct cleanup *cleanups;
  601.   char *symname = NULL;
  602.   char *filename = DEV_TTY;
  603.   struct objfile *objfile;
  604.   struct partial_symtab *ps;
  605.  
  606.   dont_repeat ();
  607.  
  608.   if (args == NULL)
  609.     {
  610.       error ("print-psymbols takes an output file name and optional symbol file name");
  611.     }
  612.   else if ((argv = buildargv (args)) == NULL)
  613.     {
  614.       nomem (0);
  615.     }
  616.   cleanups = make_cleanup (freeargv, (char *) argv);
  617.  
  618.   if (argv[0] != NULL)
  619.     {
  620.       filename = argv[0];
  621.       /* If a second arg is supplied, it is a source file name to match on */
  622.       if (argv[1] != NULL)
  623.     {
  624.       symname = argv[1];
  625.     }
  626.     }
  627.  
  628.   filename = tilde_expand (filename);
  629.   make_cleanup (free, filename);
  630.   
  631.   outfile = gdb_fopen (filename, FOPEN_WT);
  632.   if (outfile == 0)
  633.     perror_with_name (filename);
  634.   make_cleanup (fclose, outfile);
  635.  
  636.   immediate_quit++;
  637.   ALL_PSYMTABS (objfile, ps)
  638.     if (symname == NULL || (STREQ (symname, ps -> filename)))
  639.       dump_psymtab (objfile, ps, outfile);
  640.   immediate_quit--;
  641.   do_cleanups (cleanups);
  642. }
  643.  
  644. static void
  645. print_partial_symbol (p, count, what, outfile)
  646.      struct partial_symbol *p;
  647.      int count;
  648.      char *what;
  649.      GDB_FILE *outfile;
  650. {
  651.  
  652.   fprintf_filtered (outfile, "  %s partial symbols:\n", what);
  653.   while (count-- > 0)
  654.     {
  655.       fprintf_filtered (outfile, "    `%s'", SYMBOL_NAME(p));
  656.       if (SYMBOL_DEMANGLED_NAME (p) != NULL)
  657.     {
  658.       fprintf_filtered (outfile, "  `%s'", SYMBOL_DEMANGLED_NAME (p));
  659.     }
  660.       fputs_filtered (", ", outfile);
  661.       switch (SYMBOL_NAMESPACE (p))
  662.     {
  663.     case UNDEF_NAMESPACE:
  664.       fputs_filtered ("undefined namespace, ", outfile);
  665.       break;
  666.     case VAR_NAMESPACE:
  667.       /* This is the usual thing -- don't print it */
  668.       break;
  669.     case STRUCT_NAMESPACE:
  670.       fputs_filtered ("struct namespace, ", outfile);
  671.       break;
  672.     case LABEL_NAMESPACE:
  673.       fputs_filtered ("label namespace, ", outfile);
  674.       break;
  675.     default:
  676.       fputs_filtered ("<invalid namespace>, ", outfile);
  677.       break;
  678.     }
  679.       switch (SYMBOL_CLASS (p))
  680.     {
  681.     case LOC_UNDEF:
  682.       fputs_filtered ("undefined", outfile);
  683.       break;
  684.     case LOC_CONST:
  685.       fputs_filtered ("constant int", outfile);
  686.       break;
  687.     case LOC_STATIC:
  688.       fputs_filtered ("static", outfile);
  689.       break;
  690.     case LOC_REGISTER:
  691.       fputs_filtered ("register", outfile);
  692.       break;
  693.     case LOC_ARG:
  694.       fputs_filtered ("pass by value", outfile);
  695.       break;
  696.     case LOC_REF_ARG:
  697.       fputs_filtered ("pass by reference", outfile);
  698.       break;
  699.     case LOC_REGPARM:
  700.       fputs_filtered ("register parameter", outfile);
  701.       break;
  702.     case LOC_REGPARM_ADDR:
  703.       fputs_filtered ("register address parameter", outfile);
  704.       break;
  705.     case LOC_LOCAL:
  706.       fputs_filtered ("stack parameter", outfile);
  707.       break;
  708.     case LOC_TYPEDEF:
  709.       fputs_filtered ("type", outfile);
  710.       break;
  711.     case LOC_LABEL:
  712.       fputs_filtered ("label", outfile);
  713.       break;
  714.     case LOC_BLOCK:
  715.       fputs_filtered ("function", outfile);
  716.       break;
  717.     case LOC_CONST_BYTES:
  718.       fputs_filtered ("constant bytes", outfile);
  719.       break;
  720.     case LOC_LOCAL_ARG:
  721.       fputs_filtered ("shuffled arg", outfile);
  722.       break;
  723.     case LOC_OPTIMIZED_OUT:
  724.       fputs_filtered ("optimized out", outfile);
  725.       break;
  726.     default:
  727.       fputs_filtered ("<invalid location>", outfile);
  728.       break;
  729.     }
  730.       fputs_filtered (", ", outfile);
  731.       fprintf_filtered (outfile, "0x%lx\n", SYMBOL_VALUE (p));
  732.       p++;
  733.     }
  734. }
  735.  
  736. void
  737. maintenance_print_msymbols (args, from_tty)
  738.      char *args;
  739.      int from_tty;
  740. {
  741.   char **argv;
  742.   GDB_FILE *outfile;
  743.   struct cleanup *cleanups;
  744.   char *filename = DEV_TTY;
  745.   char *symname = NULL;
  746.   struct objfile *objfile;
  747.  
  748.   dont_repeat ();
  749.  
  750.   if (args == NULL)
  751.     {
  752.       error ("print-msymbols takes an output file name and optional symbol file name");
  753.     }
  754.   else if ((argv = buildargv (args)) == NULL)
  755.     {
  756.       nomem (0);
  757.     }
  758.   cleanups = make_cleanup (freeargv, argv);
  759.  
  760.   if (argv[0] != NULL)
  761.     {
  762.       filename = argv[0];
  763.       /* If a second arg is supplied, it is a source file name to match on */
  764.       if (argv[1] != NULL)
  765.     {
  766.       symname = argv[1];
  767.     }
  768.     }
  769.  
  770.   filename = tilde_expand (filename);
  771.   make_cleanup (free, filename);
  772.   
  773.   outfile = gdb_fopen (filename, FOPEN_WT);
  774.   if (outfile == 0)
  775.     perror_with_name (filename);
  776.   make_cleanup (fclose, outfile);
  777.  
  778.   immediate_quit++;
  779.   ALL_OBJFILES (objfile)
  780.     if (symname == NULL || (STREQ (symname, objfile -> name)))
  781.       dump_msymbols (objfile, outfile);
  782.   immediate_quit--;
  783.   fprintf_filtered (outfile, "\n\n");
  784.   do_cleanups (cleanups);
  785. }
  786.  
  787. void
  788. maintenance_print_objfiles (ignore, from_tty)
  789.      char *ignore;
  790.      int from_tty;
  791. {
  792.   struct objfile *objfile;
  793.  
  794.   dont_repeat ();
  795.  
  796.   immediate_quit++;
  797.   ALL_OBJFILES (objfile)
  798.     dump_objfile (objfile);
  799.   immediate_quit--;
  800. }
  801.  
  802.  
  803. /* Return the nexting depth of a block within other blocks in its symtab.  */
  804.  
  805. static int
  806. block_depth (block)
  807.      struct block *block;
  808. {
  809.   register int i = 0;
  810.   while ((block = BLOCK_SUPERBLOCK (block)) != NULL) 
  811.     {
  812.       i++;
  813.     }
  814.   return i;
  815. }
  816.  
  817. #endif    /* MAINTENANCE_CMDS */
  818.  
  819.  
  820. /* Increase the space allocated for LISTP, which is probably
  821.    global_psymbol_list or static_psymbol_list. This space will eventually
  822.    be freed in free_objfile().  */
  823.  
  824. void
  825. extend_psymbol_list (listp, objfile)
  826.      register struct psymbol_allocation_list *listp;
  827.      struct objfile *objfile;
  828. {
  829.   int new_size;
  830.   if (listp->size == 0)
  831.     {
  832.       new_size = 255;
  833.       listp->list = (struct partial_symbol *)
  834.     xmmalloc (objfile -> md, new_size * sizeof (struct partial_symbol));
  835.     }
  836.   else
  837.     {
  838.       new_size = listp->size * 2;
  839.       listp->list = (struct partial_symbol *)
  840.     xmrealloc (objfile -> md, (char *) listp->list,
  841.            new_size * sizeof (struct partial_symbol));
  842.     }
  843.   /* Next assumes we only went one over.  Should be good if
  844.      program works correctly */
  845.   listp->next = listp->list + listp->size;
  846.   listp->size = new_size;
  847. }
  848.  
  849.  
  850. /* Do early runtime initializations. */
  851. void
  852. _initialize_symmisc ()
  853. {
  854.   std_in  = stdin;
  855.   std_out = stdout;
  856.   std_err = stderr;
  857. }
  858.